<template>
  <div class="result">
    <div class="icon" :class="type === 'success' ? 'success' : 'error'">
      <Icon type="ios-checkmark" v-if="type === 'success'"></Icon>
      <Icon type="ios-close" v-if="type === 'error'"></Icon>
    </div>
    <div class="title">{{ title }}</div>
    <div class="description">{{ description }}</div>
    <div class="extra" v-if="showExtra">
      <slot name="extra"></slot>
    </div>
    <div class="actions">
      <slot name="actions"></slot>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Result',
  data() {
    return {
      showExtra: false
    }
  },
  props: {
    type: {
      type: String,
      default: 'success'
    },
    title: {
      type: String,
      default: '',
      require: true
    },
    description: {
      type: String,
      default: ''
    }
  },
  mounted() {
    this.showExtra = this.$slots.extra !== undefined
  }
}
</script>
<style scoped>
.result {
  text-align: center;
  width: 72%;
  margin: 0 auto;
  padding: 24px 0 8px;
}

.result .icon {
  font-size: 72px;
  line-height: 72px;
  margin-bottom: 24px;
}

.result .success {
  color: #52c41a;
}

.result .error {
  color: #f5222d;
}

.result .title {
  font-size: 24px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 500;
  line-height: 32px;
  margin-bottom: 16px;
}

.result .description {
  font-size: 14px;
  line-height: 22px;
  color: rgba(0, 0, 0, 0.45);
  margin-bottom: 24px;
}

.result .extra {
  background: #fafafa;
  padding: 24px 40px;
  border-radius: 2px;
  text-align: left;
}
.result .actions {
  margin-top: 32px;
}
</style>
